import requests
import parsel


headers = {
    'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/106.0.0.0 Safari/537.36'
}
resp = requests.get('https://www.xiachufang.com/', headers=headers)

selector = parsel.Selector(resp.text)
url_list = selector.css('.middle-panel div.pop-recipes.block ul li div a img::attr("src")').getall()

for item in url_list:
    url = item.split('?')[0]
    name = url.split('/')[-1]
    resp_2 = requests.get(url=url, headers=headers).content
    with open(f'img/{name}', mode='wb') as f:
        f.write(resp_2)
    print(f'{name} 保存成功！！！')


